package com.wlr.study.leetcode;

/**
 * 相交链表
 */
public class LeetCode160 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode a = headA;
        ListNode b = headB;
        if (a==b){
            return a;
        }
        while (a!=null){
            while (b!=null){
                if (a==b){
                    return a;
                }
                if (b.next==null){
                    b=headB;
                    break;
                }
                b=b.next;
            }
            a=a.next;
        }
        return null;
    }
}
